package com.atguigu.gmall.product.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lfy
 * @Description 品牌控制器
 * @create 2023-08-15 13:58
 */
@RequestMapping("/admin/product")
@RestController
public class BaseTrademarkController {


    @Autowired
    BaseTrademarkService baseTrademarkService;


    /**
     * 分页查询
     * @param pn
     * @param ps
     * @return
     */
    @GetMapping("/baseTrademark/{pn}/{ps}")
    public Result baseTrademark(@PathVariable("pn") Long pn,
                                @PathVariable("ps") Long ps){

        Page<BaseTrademark> page = baseTrademarkService.page(new Page<BaseTrademark>(pn, ps));

        return Result.ok(page);
    }


    /**
     * 按照id查询品牌
     * @param id
     * @return
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getbaseTrademarkById(@PathVariable("id")Long id){

        BaseTrademark trademark = baseTrademarkService.getById(id);
        return Result.ok(trademark);
    }


    /**
     * 保存
     * @param trademark
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result savebaseTrademark(@RequestBody BaseTrademark trademark){

        baseTrademarkService.save(trademark);
        return Result.ok();
    }

    /**
     * 按照主键更新
     * @param trademark
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result update(@RequestBody BaseTrademark trademark){

        baseTrademarkService.updateById(trademark);
        return Result.ok();
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result delete(@PathVariable("id")Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 查询品牌列表
     * @return
     */
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){

        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
